import {signout} from "../network/user";
import {sendwithget, sendwithpost} from "../network/profile";

export default {
    signOut(context) {
        signout().then(()=>{
            context.commit('signout')
        })
    },
    getAllGoods(context) {
        sendwithpost({
            url: '/getallgoods',
        }).then(res=> {
            context.commit('assignmentGoods', res.data.goods)
        })
    },
    getGoodsType(context) {
        sendwithpost({
            url: '/getgoodstype',
        }).then(res=> {
            context.commit('goodsType', res.data.data)
        })
    },
    getUser(context, payload) {
        sendwithpost({
            url: '/getUser',
        }).then(res=> {
            context.commit('changeLogn', res.data.user)
            this.dispatch('getCart')
            this.dispatch('getCoupon')
            payload.$socket.emit('lognIn', res.data.user._id)
        })
    },
    getCart(context) {
        if (context.state.lognUser) {
            sendwithpost({
                url: '/getCart',
                data: {
                    userId: context.state.lognUser._id
                }
            }).then(res=> {
                context.commit('getCart', res.data.cart);
            })
        } else {
            return
        }

    },
    getCoupon(context) {
        if (context.state.lognUser) {
            sendwithpost({
                url: '/getCoupon',
                data: {
                    userId: context.state.lognUser._id
                }
            }).then(res=> {
                // context.commit('getCoupon', res.data.cart);
            })
        } else {
            return
        }
    },
    getBusinessUser(context) {
        sendwithpost({
            url: '/getBusinessUser',
        }).then(res=> {
            context.commit('updateBusinessUser', res.data.businessUser)
        })
    },
    getSystemMessage(context) {
        sendwithget({
            url: '/brand'
        }).then(res=> {
            if (res.data.res_code == 2) {
                context.commit('updataLogoUrl', res.data.data.logoUrl)
                context.commit('updataBrand', res.data.data.brand)
            }
        })
    }

}